""" send acts like next, but makes yield return the value passed.
the function can therefore , change its behavior depending on the client code.
two other functions were added to complete this behavior throw() and close().
they raise an error into the generator

python provides a shortcut to write simple generators over a sequence. a syntax similar
to list comprehensions can be used to replace yield . parentheses are used instead of 
brackets:

    iter = (x**2 for x in range(10) if x % 2 == 0 )
    list = [x**2 for x in range(10) if x % 2 == 0 ]

"""

def psychologist():
    print 'please tell me your problems'
    while True :
        answer = (yield)
        if answer is not None:
            if answer.endswith('?'):
                print "don't ask yourself too much questions"
            elif 'good' in answer :
                print " that's good , go on"
            elif 'bad' in answer:
                print "don't be so negative"

free = psychologist()
free.next()
free.send('i feel bad')
free.send('i feel good')
free.send('i feel as?')


